<?php
/**
 * Created by PhpStorm.
 * User: lyw
 * Date: 2016/10/31
 * Time: 14:12
 */
class OrderController extends BaseController{
    public function index(){
        $doOrder = new DoZyxh_order();
        $doUser = new DoZyxh_user();
        $orderNum = $this->request('orderNum');
        $where = '';
        if($orderNum){
            $where.="orderNum = '".$orderNum."'";
        }
        $count = $doOrder->where($where)->count();
        $page = new \tools\Page($count,15);
        $orders = $doOrder->where($where)
            ->fields('id, createTime, uid, orderNum, pay_status')
            ->offset($page->limit)
            ->limit($page->pagesize)
            ->orderby('createTime desc')
            ->rows();
        foreach($orders as $k=>$v){
            $user = $doUser->fields("nickname")
                ->row($v['uid'])->data;
            $orders[$k]['nickName'] = $user['nickname'];
            $orders[$k]['pay_status'] = ($v['pay_status'] == 0) ? '未支付' : '已支付';

        }
        require $this->template;
    }
    public function detail(){
        $doOrder = new DoZyxh_order();
        $doUser = new DoZyxh_user();
        $id = $this->request('id', '', true);
        $order = $doOrder->fields('a.*, b.nickname')
            ->leftJoin($doUser, 'b', 'a.uid = b.id')
            ->where('a.id='.$id)
            ->row()->data;
        $order['sex'] = ($order['sex'] == 0) ? '女' : '男';
        $order['pay_status'] = ($order['pay_status'] == 0) ? '未支付' : '已支付';
        if($order['fid_money'] > 0 && $order['ffid_money'] > 0){
            $order['account'] = "一级".$order['fid_money']."金额 + 二级".$order['ffid_money']."金额";
        } elseif($order['fid_money'] > 0 && $order['ffid_money'] <= 0){
            $order['account'] = "一级".$order['fid_money']."金额";
        }elseif($order['ffid_money'] > 0 && $order['fid_money'] <= 0){
            $order['account'] = "二级".$order['ffid_money']."金额";
        }else{
            $order['account'] = 0;
        }
        require $this->template;
    }
}